package com.tbit.main.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tbit.main.dao.core.PowerChangeMonitorConfigDao;
import com.tbit.main.pojo.PowerChangeMonitorConfig;
import com.tbit.main.service.PowerChangeMonitorConfigService;
import com.tbit.main.util.LogUtil;
import org.springframework.stereotype.Service;

/**
 * @Author: chen
 * @Description:
 * @Date: 创建于 11:49 2023/2/20
 */
@Service
public class PowerChangeMonitorConfigServiceImpl extends ServiceImpl<PowerChangeMonitorConfigDao, PowerChangeMonitorConfig> implements
        PowerChangeMonitorConfigService {

    @Override
    public PowerChangeMonitorConfig getByAccountId(Integer accountId) {
        QueryWrapper<PowerChangeMonitorConfig> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("accountId", accountId);
        PowerChangeMonitorConfig powerChangeMonitorConfig = this.getOne(queryWrapper);
        if (powerChangeMonitorConfig == null) {
            powerChangeMonitorConfig = new PowerChangeMonitorConfig(accountId);
            this.save(powerChangeMonitorConfig);
        }
        powerChangeMonitorConfig.checkNull();
        LogUtil.info("powerChangeMonitorConfig==" + powerChangeMonitorConfig);
        return powerChangeMonitorConfig;
    }
}
